<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/jsp/sys/include.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<base href="<%=basePath%>"/>
<title>菜单管理</title>
<link href="css/global.css" type="text/css" rel="stylesheet"/>
<script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
<%--
<script src="js/popw.js" type="text/javascript"></script>
 --%>
<link rel="stylesheet" type="text/css" href="css/easydialog.css" />
	<script src="js/easydialog.min.js" type="text/javascript"></script>
	
<style type="text/css">
<!--
body{
	background-color:#ffffff;
	margin:0px; padding:0px;
}
#pageStyle{
	text-align: center;
	margin-top: 4px;
}
#control{
	margin:0px;
	padding:0Px;
	text-align: right;
}
img{
	border: 0px;
}
.parentName{
	font-weight: bold;
}
-->
</style>
<link rel="stylesheet" type="text/css" href="css/easydialog.css" />
<script src="js/easydialog.min.js" type="text/javascript"></script>
<script language="javascript">

//删除数据

function delData(data_id){
	
	
	easyDialog.open({
		overlay : true,//不加遮罩
		container : {
			header : '信息提示',
			content : '你确定要删除数据吗！',
			yesFn : function(){
		//alert(data_id);
					$.ajax({
			 			url:"sysMenuDel.do",
			 			//防止浏览器缓存，在URL后加时间戳 "&timestamp=" + (new Date()).getTime()
			 			data:encodeURI("ids=" + data_id  + "&timestamp=" + (new Date()).getTime()),
			 			dataType:"json",
			 			async: false,//同步提交
			 			success:function(data){
			 				if("true".indexOf(data+"")>-1){
			 					//form刷新防提示
			 					window.location=window.location + "&timestamp=" + (new Date()).getTime();
								window.location.reload();
			 				}else{
									easyDialog.open({
										overlay : true,//不加遮罩
										container : {
											header : '信息提示',
											content : '操作失败！',
											yesFn : function(){
												return true;
											},
											noFn : true
										}
									});
			 				}
			 			}
			 		});
		
		
				
				return false;
			
			},
			
			noFn : true
		}
	});
	
}

//更新数据
function updateData(data_id){
	var url="sysMenuUpdate.do?id="+data_id;
	//var winName = "更新用户";
	//openwindow(url,winName,600,400);
	window.location=url;
	window.reload();
}


//导出
function sysMenuExcel(){
	var exportExcelAction = "sysMenuExcel.do";
	
	var queryForm = $("#queryList");
	
	var oddAction = queryForm.attr("action");
	queryForm.attr("action",exportExcelAction);
	queryForm.get(0).submit();
	queryForm.attr("action",oddAction);
	
}

function up(data_id){

	var prevTr = $('#tr_'+data_id).prev();
	var meTr = $('#tr_'+data_id);
	
	if(prevTr.attr('parentId') != meTr.attr('parentId')){return;}
	
	var pcontent = prevTr.html();
	var pid = prevTr.attr('id');
	//如果顶层
	if(pid=="tr_00"){return;}
	
	var content = meTr.html();
	var id = meTr.attr('id');
	
	
	var meId=id.split("_")[1];
	var otherId = pid.split("_")[1];
	//alert(meId+"__"+otherId);
	var isChanged = changeOrderNum(meId, otherId);
	//如果后台没有调整成功
	if(!isChanged){return;}
	
	
	$('#tr_'+data_id).prev().html(content);
	$('#tr_'+data_id).html(pcontent);
	
	prevTr.attr('id',id);
	meTr.attr('id',pid);
	
	
	
}
function down(data_id){

	var nextTr = $('#tr_'+data_id).next();
	var meTr = $('#tr_'+data_id);
	
	if(nextTr.attr('parentId') != meTr.attr('parentId')){return;}

	var ncontent = nextTr.html();
	var nid = nextTr.attr('id');
	
	if(nid==undefined){return;	}
	
	var content = meTr.html();
	var id = meTr.attr('id');
	
	var meId=id.split("_")[1];
	var otherId = nid.split("_")[1];
	//alert(meId+"__"+otherId);
	var isChanged = changeOrderNum(meId, otherId);
	if(!isChanged){return;}
	
	$('#tr_'+data_id).next().html(content);
	$('#tr_'+data_id).html(ncontent);
	
	nextTr.attr('id',id);
	meTr.attr('id',nid);
	
}

function changeOrderNum(meId, otherId){
	var result = false;
	$.ajax({
 			url:"sysMenuChangeOrder.do",
 			//防止浏览器缓存，在URL后加时间戳 "&timestamp=" + (new Date()).getTime()
 			async: false,//同步
 			data:encodeURI("meId=" + meId + "&otherId=" + otherId + "&timestamp=" + (new Date()).getTime()),
 			dataType:"text",
 			success:function(data){
 				if(data=="true")
 				result=true;
 			}
 		});
	return result;
}


</script>
</head>
	<body>
	<%--
		<input type="button" value="showdata" onclick="javascript:alert(document.getElementById('table').innerHTML)"/>
	 --%>
		
		<div class="content">
			<form name="queryList" id="queryList" method="post" action="${pm.url}">
			
			<div id="control">
			<%--
				<a href="javascript:void(0);" onclick="javascript:sysMenuExcel();"><img src="img/excel.png" class='dotimg' title="导出EXCEL文件" /></a>&nbsp;
			 --%>
				<a href="javascript:void(0);" onclick="javascript:window.location.reload();"><img src="img/reloadme.png" class='dotimg' title="刷新" /></a>&nbsp;&nbsp;
			</div>
			
			<table id="table" class="datatable" summary="list of members in EE Studay">
				<tr id="tr_00">
					<th scope="col" >名称</th>
					<th scope="col">地址</th>
					<th scope="col">描述</th>
					<%--
					<th scope="col">序号</th>
					 --%>
					
					<th scope="col" width="180">操作</th>
				</tr>
				
				<c:forEach items="${pm.data}" var="data">
				<tr id="tr_${data.id}">
				<td <c:if test="${data.url==null}">class="parentName"</c:if>  >${data.name}
					<span style="width: 10px;">
						<span style="margin-bottom: 2px;"><a href="javascript:void(0);" onclick="javascript:up('${data.id}');"><img src="img/table-add-row-before.gif"/></a></span>
						<span style="margin-top: 1px;"><a href="javascript:void(0);" onclick="javascript:down('${data.id}');"><img src="img/table-add-row-after.gif"/></a></span>
					</span>
				
				</td>
				<td>${data.url}</td>
				<td>${data.description}</td>
				<%--
				<td>${data.orderNum}</td>
				 --%>
				<td>
				
				<span><a href="javascript:void(0);" onclick="javascript:delData('${data.id}');">删除</a>&nbsp;</span>
				<span><a href="javascript:void(0);" onclick="javascript:updateData('${data.id}');">更新</a>&nbsp;</span>
				
				</td>
				</tr>
				
				</c:forEach>
				
			</table>
			
			<div id="pageStyle">
			<%--
			${pm.pageNavigation}
			 --%>
			</div>
			
			</form>

		</div>


<script language="javascript">
$(function(){
     $("#table1").find("tr").hover(
	     function(){
	        $(this).addClass("altrow");    //鼠标经过添加hover样式
	     },
	     function(){
	        $(this).removeClass("altrow");   //鼠标离开移除hover样式
	     }
     );
});


</script>

	</body>
</html>

